import '../jquery/3.4.1/jquery.js';
import '../bootstrap/4.3.1/js/bootstrap.bundle.js';

function pageModalTip(header,content) {
	$('#myModalLabel').html(header);
	$("#pagetip").children('div:eq(0)').children('div:eq(0)').children('div:eq(1)').html(content);
	$('#pagetip').modal('show');
}

function filterIp(ip){
	let result = null;
	if (ip && ip.length>=7) {
		let point = ".";
		let ars = ip.split(point);
		if (ars.length == 4) {
			let ok = true;
			let arr = new Array();
			$.each(ars,function(i,x){
				if (ok) {
					let num = parseInt(x);
					if (Number.isInteger(num) && num>=0 && num<= 255) {
						arr.push(num);
					} else {
						ok = false;
					}
				} else {
					ok = false;
				}
			});
			if (ok) {
				result = arr.join(point);
			}
		}
	}
	return result;
}

function filterPort(port){
	let result = null;
	if (port) {
		let num = parseInt(port);
		if (Number.isInteger(num) && num>=0 && num<= 65535) {
			result = num;
		}
	}
	return result;
}

export {pageModalTip, filterIp, filterPort};